package eu.winterwheels.enterprise.model;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.Email;

@Entity
public class User implements Serializable {
	/** Default value included to remove warning. Remove or modify at will. **/
	private static final long serialVersionUID = 1L;

	/***** ATTRIBUTES *****/
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	// TODO Must set initial value of user number to 100000 or 50000
	// @SequenceGenerator(name = "UserSeqGen", initialValue = 10000)
	private Long id;
	
	@ManyToMany
	private Set<Role> roles;

	@Size(min = 2, max = 100)
	@Pattern(regexp = "[A-Za-z ]*", message = " must contain only letters and spaces")
	private String username;
	private String surname;
	private String givenname;

	private String password;
	@Email
	private String email;

	@Size(min = 9, max = 15)
	// @Digits(fraction = 0, integer = 15)
	// @Column(name = "phone")
	private String phone;
	private String mobile;
	private String fax;

	private Date dateCreated;
	private Date dateModified;

	/***** EVENT HOOKS *****/

	@PrePersist
	protected void onCreate() {
		dateCreated = new Date();
	}

	@PreUpdate
	protected void onUpdate() {
		dateModified = new Date();
	}

	/***** GETTER AND SETTERS *****/

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getGivenname() {
		return givenname;
	}

	public void setGivenname(String givenname) {
		this.givenname = givenname;
	}

	public String getSurname() {
		return surname;
	}

	public void setSurname(String surname) {
		this.surname = surname;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

}